package com.jy.wms.controller;

import com.github.pagehelper.Page;
import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.base.BaseController;
import com.jy.wms.common.base.BaseSessionInfo;
import com.jy.wms.common.base.ResultPage;
import com.jy.wms.pojo.SysHz;
import com.jy.wms.pojo.WmsStoreHouse;
import com.jy.wms.service.WmsStoreHouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 * @ClassName: WmsStoreHouseController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author lqc
 * @Date Thu Jun 28 14:23:30 CST 2018
 */
@RestController
@RequestMapping("/wmsstorehouse")
@Api(value = "/wmsstorehouse", description = "期初期末查询")
public class  WmsStoreHouseController extends BaseController<WmsStoreHouseService,WmsStoreHouse> {

    @PostMapping(value = {"list", ""})
    @ApiOperation(value = "期初期末", response = JSONObject.class, notes = "查询信息")
    public @ResponseBody
    ResultPage<WmsStoreHouse> getWmsStoreHouse(@RequestBody WmsStoreHouse entity, HttpSession session) {
        ////获取当前操作用户的货主id
        List<SysHz> hz = (List<SysHz>) session.getAttribute(BaseSessionInfo.SessionConsignor);
        String hzid = hz.get(0).getHzid();
        //获取仓库Id
        UserInfo userinfo = (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
        String ckid = userinfo.getUser().getOrgId().get(0).toString();
        entity.setHpid(hzid);
        entity.setCkid(ckid);
        //获取时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        long start = Long.parseLong(entity.getStart());
        long End = Long.parseLong(entity.getEnd());
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(start);
        java.util.Date date = c.getTime();
        String start_time = sdf.format(date);
        c.setTimeInMillis(End);
        java.util.Date date2 = c.getTime();
        String End_time = sdf.format(date2);

        entity.setStart(start_time);
        entity.setEnd(End_time);

        Page<WmsStoreHouse> list = baseService.baseSelectPage(entity);
        return renderPage(list);
    }

    @PostMapping(value = "WmsStoreHouseTimer")
    @ApiOperation(value = "定时器",response = JSONObject.class, notes = "定时器查询")
    public @ResponseBody void getWmsStoreHouseById() throws ParseException {
        baseService.baseSelectByPrimaryKey();
    }

}
